Imports Microsoft.DirectX.Direct3D

Namespace Libs

    Module mImageLibrarys

        Public Interface1c As MirImageLibrary
        Public GameInter As MirImageLibrary
        Public GameInter1 As MirImageLibrary
        Public Magic As MirImageLibrary
        Public EvoInterface As MirImageLibrary

        Public TileSC As MirImageLibrary
        Public Tiles5C As MirImageLibrary
        Public TileS30C As MirImageLibrary
        Public SMTileSC As MirImageLibrary
        Public HouseSC As MirImageLibrary
        Public CliffSC As MirImageLibrary
        Public DungeonSC As MirImageLibrary
        Public InnerSC As MirImageLibrary
        Public FurnitureSC As MirImageLibrary
        Public WallSC As MirImageLibrary
        Public SMObjectSC As MirImageLibrary
        Public AnimationSC As MirImageLibrary
        Public Object1C As MirImageLibrary
        Public Object2C As MirImageLibrary

        Public WoodTileSC As MirImageLibrary
        Public WoodTiles5C As MirImageLibrary
        Public WoodHouseSC As MirImageLibrary
        Public WoodCliffSC As MirImageLibrary
        Public WoodFurnitureSC As MirImageLibrary
        Public WoodSMObjectSC As MirImageLibrary
        Public WoodDungeonSC As MirImageLibrary
        Public WoodInnerSC As MirImageLibrary

        Public MHum As MirImageLibrary
        Public MHumEx1 As MirImageLibrary
        Public MHumA As MirImageLibrary
        Public MHumAEx1 As MirImageLibrary
        Public WMHum As MirImageLibrary
        Public WMHumEx1 As MirImageLibrary
        Public WMHumA As MirImageLibrary
        Public WMHumAEx1 As MirImageLibrary

        Public MHair As MirImageLibrary
        Public MHairA As MirImageLibrary
        Public WMHair As MirImageLibrary
        Public WMHairA As MirImageLibrary

        Public MHelmet1 As MirImageLibrary
        Public MHelmet2 As MirImageLibrary
        Public MHelmetA1 As MirImageLibrary
        Public MHelmetA2 As MirImageLibrary
        Public WMHelmet1 As MirImageLibrary
        Public WMHelmet2 As MirImageLibrary
        Public WMHelmetA1 As MirImageLibrary
        Public WMHelmetA2 As MirImageLibrary

        Public MWeapon1 As MirImageLibrary
        Public MWeapon2 As MirImageLibrary
        Public MWeapon3 As MirImageLibrary
        Public MWeapon4 As MirImageLibrary
        Public MWeapon5 As MirImageLibrary
        Public MWeapon6 As MirImageLibrary
        Public MWeapon7 As MirImageLibrary
        Public MWeapon10 As MirImageLibrary
        Public MWeapon11 As MirImageLibrary
        Public MWeaponADL1 As MirImageLibrary
        Public MWeaponADR1 As MirImageLibrary
        Public MWeaponAOH1 As MirImageLibrary
        Public MWeaponAOH2 As MirImageLibrary
        Public WMWeapon1 As MirImageLibrary
        Public WMWeapon2 As MirImageLibrary
        Public WMWeapon3 As MirImageLibrary
        Public WMWeapon4 As MirImageLibrary
        Public WMWeapon5 As MirImageLibrary
        Public WMWeapon6 As MirImageLibrary
        Public WMWeapon7 As MirImageLibrary
        Public WMWeapon10 As MirImageLibrary
        Public WMWeapon11 As MirImageLibrary
        Public WMWeaponADL1 As MirImageLibrary
        Public WMWeaponADR1 As MirImageLibrary
        Public WMWeaponAOH1 As MirImageLibrary
        Public WMWeaponAOH2 As MirImageLibrary

        Public Inventory As MirImageLibrary
        Public Equip As MirImageLibrary
        Public Storeitem As MirImageLibrary
        Public ProgUse As MirImageLibrary

        Public MonImg As MirImageLibrary

        Public Mon() As MirImageLibrary
        Public MonS() As MirImageLibrary

        Private intLib_Mon(255) As Integer
        Private intLib_MonS(255) As Integer

        Public Ground As MirImageLibrary
        Public MIcon As MirImageLibrary

        Public Horse As MirImageLibrary
        Public HorseS As MirImageLibrary

        Public Fmmap As MirImageLibrary
        Public NPC As MirImageLibrary

        Public Sub Init()

            Interface1c = New MirImageLibrary("Interface1c")
            GameInter = New MirImageLibrary("GameInter")
            GameInter1 = New MirImageLibrary("GameInter1")

            Magic = New MirImageLibrary("Magic")

            MHum = New MirImageLibrary("M-Hum")
            MHumEx1 = New MirImageLibrary("M-HumEx1")
            'MHumA = New MirImageLibrary("M-HumA")
            'MHumAEx1 = New MirImageLibrary("M-HumAEx1")

            WMHum = New MirImageLibrary("WM-Hum")
            WMHumEx1 = New MirImageLibrary("WM-HumEx1")
            'WMHumA = New MirImageLibrary("WM-HumA")
            'WMHumAEx1 = New MirImageLibrary("WM-HumAEx1")

            MHair = New MirImageLibrary("M-Hair")
            'MHairA = New MirImageLibrary("M-HairA")

            WMHair = New MirImageLibrary("WM-Hair")
            'WMHairA = New MirImageLibrary("WM-HairA")

            MHelmet1 = New MirImageLibrary("M-Helmet1")
            MHelmet2 = New MirImageLibrary("M-Helmet2")
            'MHelmetA1 = New MirImageLibrary("M-HelmetA1")
            'MHelmetA2 = New MirImageLibrary("M-HelmetA2")

            WMHelmet1 = New MirImageLibrary("WM-Helmet1")
            WMHelmet2 = New MirImageLibrary("WM-Helmet2")
            'WMHelmetA1 = New MirImageLibrary("WM-HelmetA1")
            'WMHelmetA2 = New MirImageLibrary("WM-HelmetA2")

            MWeapon1 = New MirImageLibrary("M-Weapon1")
            MWeapon2 = New MirImageLibrary("M-Weapon2")
            MWeapon3 = New MirImageLibrary("M-Weapon3")
            MWeapon4 = New MirImageLibrary("M-Weapon4")
            MWeapon5 = New MirImageLibrary("M-Weapon5")
            MWeapon6 = New MirImageLibrary("M-Weapon6")
            MWeapon7 = New MirImageLibrary("M-Weapon7")
            MWeapon10 = New MirImageLibrary("M-Weapon10")
            'MWeapon11 = New MirImageLibrary("M-Weapon11")
            'MWeaponADL1 = New MirImageLibrary("M-WeaponADL1")
            'MWeaponADR1 = New MirImageLibrary("M-WeaponADR1")
            'MWeaponAOH1 = New MirImageLibrary("M-WeaponAOH1")
            'MWeaponAOH2 = New MirImageLibrary("M-WeaponAOH2")

            WMWeapon1 = New MirImageLibrary("WM-Weapon1")
            WMWeapon2 = New MirImageLibrary("WM-Weapon2")
            WMWeapon3 = New MirImageLibrary("WM-Weapon3")
            WMWeapon4 = New MirImageLibrary("WM-Weapon4")
            WMWeapon5 = New MirImageLibrary("WM-Weapon5")
            WMWeapon6 = New MirImageLibrary("WM-Weapon6")
            WMWeapon7 = New MirImageLibrary("WM-Weapon7")
            WMWeapon10 = New MirImageLibrary("WM-Weapon10")
            'WMWeapon11 = New MirImageLibrary("WM-Weapon11")
            'WMWeaponADL1 = New MirImageLibrary("WM-WeaponADL1")
            'WMWeaponADR1 = New MirImageLibrary("WM-WeaponADR1")
            'WMWeaponAOH1 = New MirImageLibrary("WM-WeaponAOH1")
            'WMWeaponAOH2 = New MirImageLibrary("WM-WeaponAOH2")

            EvoInterface = New MirImageLibrary("Evo\evointerface")

            Inventory = New MirImageLibrary("inventory")
            Equip = New MirImageLibrary("Equip")
            Storeitem = New MirImageLibrary("Storeitem")
            ProgUse = New MirImageLibrary("ProgUse")

            MonImg = New MirImageLibrary("MonImg")

            TileSC = New MirImageLibrary("Tilesc")
            TileS30C = New MirImageLibrary("Tiles30c")
            Tiles5C = New MirImageLibrary("tiles5c")
            SMTileSC = New MirImageLibrary("smtilesc")
            HouseSC = New MirImageLibrary("Housesc")
            CliffSC = New MirImageLibrary("Cliffsc")
            DungeonSC = New MirImageLibrary("dungeonsc")
            InnerSC = New MirImageLibrary("innersc")
            FurnitureSC = New MirImageLibrary("furnituresc")
            WallSC = New MirImageLibrary("wallsc")
            SMObjectSC = New MirImageLibrary("SMObjectsc")
            Object1C = New MirImageLibrary("Object1c")
            Object2C = New MirImageLibrary("Object2c")


            WoodTileSC = New MirImageLibrary("wood\Tilesc")

            WoodTiles5C = New MirImageLibrary("wood\tiles5c")
            WoodHouseSC = New MirImageLibrary("wood\Housesc")
            WoodCliffSC = New MirImageLibrary("wood\Cliffsc")

            WoodDungeonSC = New MirImageLibrary("wood\dungeonsc")

            WoodFurnitureSC = New MirImageLibrary("Wood\Furnituresc")

            WoodSMObjectSC = New MirImageLibrary("wood\smobjectsc")
            WoodInnerSC = New MirImageLibrary("wood\innersc")

            AnimationSC = New MirImageLibrary("Animationsc")

            Ground = New MirImageLibrary("Ground")
            MIcon = New MirImageLibrary("MIcon")

            Horse = New MirImageLibrary("Horse")
            HorseS = New MirImageLibrary("HorseS")

            Fmmap = New MirImageLibrary("Fmmap")

            NPC = New MirImageLibrary("NPC")

            'init Mon libs

            'get a list of files in Data dir
            Dim DI As New IO.DirectoryInfo(Globals.sDataPath)
            Dim FI As IO.FileInfo() = DI.GetFiles("*.wil")

            Dim idxLib As Integer
            Dim idxLibS As Integer

            'itterate through the files looking for Mon and MonS files (mob pics, and shadows)
            For Each info As IO.FileInfo In FI

                If info.Name.Substring(0, 4) = "Mon-" Then

                    intLib_Mon(idxLib) = info.Name.Substring(4, info.Name.Length - 8)
                    idxLib += 1

                ElseIf info.Name.Substring(0, 5) = "MonS-" Then

                    intLib_MonS(idxLibS) = info.Name.Substring(5, info.Name.Length - 9)
                    idxLibS += 1

                End If

            Next

            ReDim Mon(idxLib)
            ReDim MonS(idxLib)

            For i As Integer = 0 To idxLib - 1

                Mon(i) = New MirImageLibrary("Mon-" & intLib_Mon(i))

            Next

            For i As Integer = 0 To idxLibS - 1

                MonS(i) = New MirImageLibrary("Mons-" & intLib_MonS(i))

            Next

        End Sub

        Public Sub Shutdown()

            If Interface1c Is Nothing Then Exit Sub

            Interface1c.Dispose()
            GameInter.Dispose()
            GameInter1.Dispose()

            Magic.Dispose()

            MHum.Dispose()
            MHumEx1.Dispose()
            'MHumA.Dispose()
            'MHumAEx1.Dispose()

            WMHum.Dispose()
            WMHumEx1.Dispose()
            'WMHumA.Dispose()
            'WMHumAEx1.Dispose()

            MHair.Dispose()
            'MHairA.Dispose()

            WMHair.Dispose()
            'WMHairA.Dispose()

            MHelmet1.Dispose()
            MHelmet2.Dispose()
            'MHelmetA1.Dispose()
            'MHelmetA2.Dispose()

            WMHelmet1.Dispose()
            WMHelmet2.Dispose()
            'WMHelmetA1.Dispose()
            'WMHelmetA2.Dispose()

            MWeapon1.Dispose()
            MWeapon2.Dispose()
            MWeapon3.Dispose()
            MWeapon4.Dispose()
            MWeapon5.Dispose()
            MWeapon6.Dispose()
            MWeapon7.Dispose()
            MWeapon10.Dispose()
            'MWeapon11.Dispose()
            'MWeaponADL1.Dispose()
            'MWeaponADR1.Dispose()
            'MWeaponAOH1.Dispose()
            'MWeaponAOH2.Dispose()

            WMWeapon1.Dispose()
            WMWeapon2.Dispose()
            WMWeapon3.Dispose()
            WMWeapon4.Dispose()
            WMWeapon5.Dispose()
            WMWeapon6.Dispose()
            WMWeapon7.Dispose()
            WMWeapon10.Dispose()
            'WMWeapon11.Dispose()
            'WMWeaponADL1.Dispose()
            'WMWeaponADR1.Dispose()
            'WMWeaponAOH1.Dispose()
            'WMWeaponAOH2.Dispose()

            EvoInterface.Dispose()

            Inventory.Dispose()
            Equip.Dispose()
            Storeitem.Dispose()

            ProgUse.Dispose()

            MonImg.Dispose()

            TileSC.Dispose()
            Tiles5C.Dispose()
            TileS30C.Dispose()
            SMTileSC.Dispose()
            HouseSC.Dispose()
            CliffSC.Dispose()
            DungeonSC.Dispose()
            InnerSC.Dispose()
            FurnitureSC.Dispose()
            WallSC.Dispose()
            SMObjectSC.Dispose()
            AnimationSC.Dispose()
            Object1C.Dispose()
            Object2C.Dispose()

            WoodTileSC.Dispose()
            WoodTiles5C.Dispose()
            WoodHouseSC.Dispose()
            WoodCliffSC.Dispose()
            WoodFurnitureSC.Dispose()
            WoodSMObjectSC.Dispose()
            WoodDungeonSC.Dispose()
            WoodInnerSC.Dispose()

            AnimationSC.Dispose()

            Ground.Dispose()
            MIcon.Dispose()

            Horse.Dispose()
            HorseS.Dispose()

            Fmmap.Dispose()
            NPC.Dispose()


            'dispose of Mon files in the arrays
            For Each imglib As MirImageLibrary In Mon
                If Not imglib Is Nothing Then
                    imglib.Dispose()
                End If
            Next

            For Each imglib As MirImageLibrary In MonS
                If Not imglib Is Nothing Then
                    imglib.Dispose()
                End If
            Next

        End Sub

        Public Function GetLib(ByRef imglib As EvoLib.Protocol.ImgLibs) As MirImageLibrary

            Select Case imglib
                Case EvoLib.Protocol.ImgLibs.Interface1c
                    Return Interface1c
                Case EvoLib.Protocol.ImgLibs.GameInter
                    Return GameInter
                Case EvoLib.Protocol.ImgLibs.GameInter1
                    Return GameInter1
                Case EvoLib.Protocol.ImgLibs.Magic
                    Return Magic
                Case EvoLib.Protocol.ImgLibs.EvoInterface
                    Return EvoInterface
                Case EvoLib.Protocol.ImgLibs.TileSC
                    Return TileSC
                Case EvoLib.Protocol.ImgLibs.Tiles5C
                    Return Tiles5C
                Case EvoLib.Protocol.ImgLibs.TileS30C
                    Return TileS30C
                Case EvoLib.Protocol.ImgLibs.HouseSC
                    Return HouseSC
                Case EvoLib.Protocol.ImgLibs.CliffSC
                    Return CliffSC
                Case EvoLib.Protocol.ImgLibs.SMObjectSC
                    Return SMObjectSC
                Case EvoLib.Protocol.ImgLibs.SmTileSC
                    Return SMTileSC
                Case EvoLib.Protocol.ImgLibs.DungeonSC
                    Return DungeonSC
                Case EvoLib.Protocol.ImgLibs.InnerSC
                    Return InnerSC
                Case EvoLib.Protocol.ImgLibs.FurnitureSC
                    Return FurnitureSC
                Case EvoLib.Protocol.ImgLibs.WallSC
                    Return WallSC
                Case EvoLib.Protocol.ImgLibs.WoodTiles5C
                    Return WoodTiles5C
                Case EvoLib.Protocol.ImgLibs.WoodFurnitureSC
                    Return WoodFurnitureSC
                Case EvoLib.Protocol.ImgLibs.WoodSMObjectSC
                    Return WoodSMObjectSC
                Case EvoLib.Protocol.ImgLibs.WoodDungeonSC
                    Return WoodDungeonSC
                Case EvoLib.Protocol.ImgLibs.WoodInnerSC
                    Return WoodInnerSC
                Case EvoLib.Protocol.ImgLibs.Objects1C
                    Return Object1C
                Case EvoLib.Protocol.ImgLibs.Object2C
                    Return Object2C
                Case EvoLib.Protocol.ImgLibs.WoodTileSC
                    Return WoodTileSC
                Case EvoLib.Protocol.ImgLibs.WoodHouseSC
                    Return WoodHouseSC
                Case EvoLib.Protocol.ImgLibs.WoodCliffSC
                    Return WoodCliffSC
                Case EvoLib.Protocol.ImgLibs.AnimationSC
                    Return AnimationSC

                Case EvoLib.Protocol.ImgLibs.MHum
                    Return MHum
                Case EvoLib.Protocol.ImgLibs.MHumEx1
                    Return MHumEx1
                Case EvoLib.Protocol.ImgLibs.MHumA
                    Return MHumA
                Case EvoLib.Protocol.ImgLibs.MHumAEx1
                    Return MHumAEx1

                Case EvoLib.Protocol.ImgLibs.WMHum
                    Return WMHum
                Case EvoLib.Protocol.ImgLibs.WMHumEx1
                    Return WMHumEx1
                Case EvoLib.Protocol.ImgLibs.WMHumA
                    Return WMHumA
                Case EvoLib.Protocol.ImgLibs.WMHumAEx1
                    Return WMHumAEx1

                Case EvoLib.Protocol.ImgLibs.MHair
                    Return MHair
                Case EvoLib.Protocol.ImgLibs.MHairA
                    Return MHairA

                Case EvoLib.Protocol.ImgLibs.WMHair
                    Return WMHair
                Case EvoLib.Protocol.ImgLibs.WMHairA
                    Return WMHairA

                Case EvoLib.Protocol.ImgLibs.MHelmet1
                    Return MHelmet1
                Case EvoLib.Protocol.ImgLibs.MHelmet2
                    Return MHelmet2
                Case EvoLib.Protocol.ImgLibs.MHelmetA1
                    Return MHelmetA1
                Case EvoLib.Protocol.ImgLibs.MHelmetA2
                    Return MHelmetA2

                Case EvoLib.Protocol.ImgLibs.WMHelmet1
                    Return WMHelmet1
                Case EvoLib.Protocol.ImgLibs.WMHelmet2
                    Return WMHelmet2
                Case EvoLib.Protocol.ImgLibs.WMHelmetA1
                    Return WMHelmetA1
                Case EvoLib.Protocol.ImgLibs.WMHelmetA2
                    Return WMHelmetA2

                Case EvoLib.Protocol.ImgLibs.MWeapon1
                    Return MWeapon1
                Case EvoLib.Protocol.ImgLibs.MWeapon2
                    Return MWeapon2
                Case EvoLib.Protocol.ImgLibs.MWeapon3
                    Return MWeapon3
                Case EvoLib.Protocol.ImgLibs.MWeapon4
                    Return MWeapon4
                Case EvoLib.Protocol.ImgLibs.MWeapon5
                    Return MWeapon5
                Case EvoLib.Protocol.ImgLibs.MWeapon6
                    Return MWeapon6
                Case EvoLib.Protocol.ImgLibs.MWeapon7
                    Return MWeapon7
                Case EvoLib.Protocol.ImgLibs.MWeapon10
                    Return MWeapon10
                Case EvoLib.Protocol.ImgLibs.MWeapon11
                    Return MWeapon11
                Case EvoLib.Protocol.ImgLibs.MWeaponADL1
                    Return MWeaponADL1
                Case EvoLib.Protocol.ImgLibs.MWeaponADR1
                    Return MWeaponADR1
                Case EvoLib.Protocol.ImgLibs.MWeaponAOH1
                    Return MWeaponAOH1
                Case EvoLib.Protocol.ImgLibs.MWeaponAOH2
                    Return MWeaponAOH2

                Case EvoLib.Protocol.ImgLibs.WMWeapon1
                    Return WMWeapon1
                Case EvoLib.Protocol.ImgLibs.WMWeapon2
                    Return WMWeapon2
                Case EvoLib.Protocol.ImgLibs.WMWeapon3
                    Return WMWeapon3
                Case EvoLib.Protocol.ImgLibs.WMWeapon4
                    Return WMWeapon4
                Case EvoLib.Protocol.ImgLibs.WMWeapon5
                    Return WMWeapon5
                Case EvoLib.Protocol.ImgLibs.WMWeapon6
                    Return WMWeapon6
                Case EvoLib.Protocol.ImgLibs.WMWeapon7
                    Return WMWeapon7
                Case EvoLib.Protocol.ImgLibs.WMWeapon10
                    Return WMWeapon10
                Case EvoLib.Protocol.ImgLibs.WMWeapon11
                    Return WMWeapon11
                Case EvoLib.Protocol.ImgLibs.WMWeaponADL1
                    Return WMWeaponADL1
                Case EvoLib.Protocol.ImgLibs.WMWeaponADR1
                    Return WMWeaponADR1
                Case EvoLib.Protocol.ImgLibs.WMWeaponAOH1
                    Return WMWeaponAOH1
                Case EvoLib.Protocol.ImgLibs.WMWeaponAOH2
                    Return WMWeaponAOH2

                Case EvoLib.Protocol.ImgLibs.Inventory
                    Return Inventory
                Case EvoLib.Protocol.ImgLibs.Equip
                    Return Equip
                Case EvoLib.Protocol.ImgLibs.ProgUse
                    Return ProgUse

                Case EvoLib.Protocol.ImgLibs.MonImg
                    Return MonImg

                Case EvoLib.Protocol.ImgLibs.Ground
                    Return Ground

                Case EvoLib.Protocol.ImgLibs.MIcon
                    Return MIcon

                Case EvoLib.Protocol.ImgLibs.Horse
                    Return Horse

                Case EvoLib.Protocol.ImgLibs.HorseS
                    Return HorseS

                Case EvoLib.Protocol.ImgLibs.Fmmap
                    Return Fmmap

                Case EvoLib.Protocol.ImgLibs.NPC
                    Return NPC

                Case EvoLib.Protocol.ImgLibs.StoreItem
                    Return Storeitem

                Case Else
                    'is this a Mon or MonS lib
                    If imglib > EvoLib.Protocol.StartOfMonLibs - 1 Then
                        Dim R As Integer
                        Dim MonNum As Integer = (Math.DivRem((imglib - (EvoLib.Protocol.StartOfMonLibs - 2)), 2, R))
                        If R = 0 Then
                            'Mon libs
                            For i As Integer = 0 To 255
                                If intLib_Mon(i) = MonNum Then Return Mon(i)
                            Next
                        Else
                            'MonS libs
                            For i As Integer = 0 To 255
                                If intLib_MonS(i) = MonNum Then Return MonS(i)
                            Next
                        End If
                    End If

                    Return Nothing

            End Select

        End Function

        Public Structure LibShapePair
            Dim library As EvoLib.Protocol.ImgLibs
            Dim shape As Integer
        End Structure

        Public Function GetArmourLib(ByRef gender As EvoLib.Protocol.Gender, ByRef shape As Integer) As LibShapePair

            Dim ret As New LibShapePair

            Select Case shape

                Case 0 To 9
                    ret.shape = shape
                Case 10 To 19
                    ret.shape = shape - 10
                Case 20 To 29
                    ret.shape = shape - 20
                Case 30 To 39
                    ret.shape = shape - 30

            End Select

            Select Case gender

                Case EvoLib.Protocol.Gender.Male
                    Select Case shape
                        Case 0 To 9
                            ret.library = EvoLib.Protocol.ImgLibs.MHum
                        Case 10 To 19
                            ret.library = EvoLib.Protocol.ImgLibs.MHumEx1
                        Case 20 To 29
                            ret.library = EvoLib.Protocol.ImgLibs.MHumA
                        Case 30 To 39
                            ret.library = EvoLib.Protocol.ImgLibs.MHumAEx1
                    End Select

                Case EvoLib.Protocol.Gender.Female
                    Select Case shape
                        Case 0 To 9
                            ret.library = EvoLib.Protocol.ImgLibs.WMHum
                        Case 10 To 19
                            ret.library = EvoLib.Protocol.ImgLibs.WMHumEx1
                        Case 20 To 29
                            ret.library = EvoLib.Protocol.ImgLibs.WMHumA
                        Case 30 To 39
                            ret.library = EvoLib.Protocol.ImgLibs.WMHumAEx1
                    End Select

            End Select

            Return ret

        End Function

        Public Function GetHeadLib(ByRef gender As EvoLib.Protocol.Gender, ByRef shape As Integer, ByRef ishelm As Boolean) As LibShapePair

            Dim ret As New LibShapePair

            Select Case shape

                Case -1 To 9
                    ret.shape = shape
                Case 10 To 19
                    ret.shape = shape - 10
                Case 20 To 29
                    ret.shape = shape - 20
                Case 30 To 39
                    ret.shape = shape - 30

            End Select

            Select Case gender

                Case EvoLib.Protocol.Gender.Male
                    If ishelm Then
                        Select Case shape
                            Case -1 To 9
                                ret.library = EvoLib.Protocol.ImgLibs.MHelmet1
                            Case 10 To 19
                                ret.library = EvoLib.Protocol.ImgLibs.MHelmet2
                            Case 20 To 29
                                ret.library = EvoLib.Protocol.ImgLibs.MHelmetA1
                            Case 30 To 39
                                ret.library = EvoLib.Protocol.ImgLibs.MHelmetA2
                        End Select

                    Else

                        Select Case shape
                            Case 0 To 9
                                ret.library = EvoLib.Protocol.ImgLibs.MHair
                            Case 10 To 19
                                ret.library = EvoLib.Protocol.ImgLibs.MHairA

                        End Select

                    End If

                Case EvoLib.Protocol.Gender.Female
                    If ishelm Then
                        Select Case shape
                            Case -1 To 9
                                ret.library = EvoLib.Protocol.ImgLibs.WMHelmet1
                            Case 10 To 19
                                ret.library = EvoLib.Protocol.ImgLibs.WMHelmet2
                            Case 20 To 29
                                ret.library = EvoLib.Protocol.ImgLibs.WMHelmetA1
                            Case 30 To 39
                                ret.library = EvoLib.Protocol.ImgLibs.WMHelmetA2
                        End Select

                    Else

                        Select Case shape
                            Case 0 To 9
                                ret.library = EvoLib.Protocol.ImgLibs.WMHair
                            Case 10 To 19
                                ret.library = EvoLib.Protocol.ImgLibs.WMHairA
                        End Select

                    End If

            End Select

            Return ret

        End Function

        Public Function GetWeaponLib(ByRef gender As EvoLib.Protocol.Gender, ByRef shape As Integer) As LibShapePair

            Dim ret As New LibShapePair

            Select Case shape

                Case -1 To 9
                    ret.shape = shape
                Case 10 To 19
                    ret.shape = shape - 10
                Case 20 To 29
                    ret.shape = shape - 20
                Case 30 To 39
                    ret.shape = shape - 30
                Case 40 To 49
                    ret.shape = shape - 40
                Case 50 To 59
                    ret.shape = shape - 50
                Case 60 To 69
                    ret.shape = shape - 60
                Case 70 To 79
                    ret.shape = shape - 70
                Case 80 To 89
                    ret.shape = shape - 80
                Case 90 To 99
                    ret.shape = shape - 90
                Case 100 To 109
                    ret.shape = shape - 100
                Case 110 To 119
                    ret.shape = shape - 110
                Case 120 To 129
                    ret.shape = shape - 120

            End Select

            Select Case gender

                Case EvoLib.Protocol.Gender.Male
                    Select Case shape
                        Case -1 To 9
                            ret.library = EvoLib.Protocol.ImgLibs.MWeapon1
                        Case 10 To 19
                            ret.library = EvoLib.Protocol.ImgLibs.MWeapon2
                        Case 20 To 29
                            ret.library = EvoLib.Protocol.ImgLibs.MWeapon3
                        Case 30 To 39
                            ret.library = EvoLib.Protocol.ImgLibs.MWeapon4
                        Case 40 To 49
                            ret.library = EvoLib.Protocol.ImgLibs.MWeapon5
                        Case 50 To 59
                            ret.library = EvoLib.Protocol.ImgLibs.MWeapon6
                        Case 60 To 69
                            ret.library = EvoLib.Protocol.ImgLibs.MWeapon7
                        Case 70 To 79
                            ret.library = EvoLib.Protocol.ImgLibs.MWeapon10
                        Case 80 To 89
                            ret.library = EvoLib.Protocol.ImgLibs.MWeapon11
                        Case 90 To 99
                            ret.library = EvoLib.Protocol.ImgLibs.MWeaponADL1
                        Case 100 To 109
                            ret.library = EvoLib.Protocol.ImgLibs.MWeaponADR1
                        Case 110 To 119
                            ret.library = EvoLib.Protocol.ImgLibs.MWeaponAOH1
                        Case 120 To 129
                            ret.library = EvoLib.Protocol.ImgLibs.MWeaponAOH2
                    End Select

                Case EvoLib.Protocol.Gender.Female
                    Select Case shape
                        Case -1 To 9
                            ret.library = EvoLib.Protocol.ImgLibs.WMWeapon1
                        Case 10 To 19
                            ret.library = EvoLib.Protocol.ImgLibs.WMWeapon2
                        Case 20 To 29
                            ret.library = EvoLib.Protocol.ImgLibs.WMWeapon3
                        Case 30 To 39
                            ret.library = EvoLib.Protocol.ImgLibs.WMWeapon4
                        Case 40 To 49
                            ret.library = EvoLib.Protocol.ImgLibs.WMWeapon5
                        Case 50 To 59
                            ret.library = EvoLib.Protocol.ImgLibs.WMWeapon6
                        Case 60 To 69
                            ret.library = EvoLib.Protocol.ImgLibs.WMWeapon7
                        Case 70 To 79
                            ret.library = EvoLib.Protocol.ImgLibs.WMWeapon10
                        Case 80 To 89
                            ret.library = EvoLib.Protocol.ImgLibs.WMWeapon11
                        Case 90 To 99
                            ret.library = EvoLib.Protocol.ImgLibs.WMWeaponADL1
                        Case 100 To 109
                            ret.library = EvoLib.Protocol.ImgLibs.WMWeaponADR1
                        Case 110 To 119
                            ret.library = EvoLib.Protocol.ImgLibs.WMWeaponAOH1
                        Case 120 To 129
                            ret.library = EvoLib.Protocol.ImgLibs.WMWeaponAOH2
                    End Select

            End Select

            Return ret

        End Function

        Public Function GetMobLib(ByVal shape As Integer) As LibShapePair

            Dim ls As LibShapePair

            Dim R As Integer
            Dim L As Integer = Math.DivRem(shape, 10, R)
            ls.shape = R

            ls.library = EvoLib.Protocol.StartOfMonLibs + (L * 2)

            Return ls

        End Function

        Public Function GetMobShadowLib(ByVal shape As Integer) As LibShapePair

            Dim ls As LibShapePair

            Dim R As Integer
            Dim L As Integer = Math.DivRem(shape, 10, R)
            ls.shape = R

            shape += 11

            Math.DivRem(shape, 10, Nothing)

            ls.library = (EvoLib.Protocol.StartOfMonLibs - 1) + (L * 2)

            Return ls

        End Function


        Public Function GetMagicLib(ByRef shape As Integer) As LibShapePair

            Dim ret As New LibShapePair

            Select Case shape

                Case 0 To 10
                    ret.shape = shape
                Case 11 To 21
                    ret.shape = shape - 11
                Case 22 To 32
                    ret.shape = shape - 22
                Case 33 To 43
                    ret.shape = shape - 33
                Case 44 To 54
                    ret.shape = shape - 44
                Case 55 To 65
                    ret.shape = shape - 55
                Case 66 To 76
                    ret.shape = shape - 66
                Case 77 To 87
                    ret.shape = shape - 77
                Case 88 To 98
                    ret.shape = shape - 88
                Case 99 To 109
                    ret.shape = shape - 99
                Case 110 To 120
                    ret.shape = shape - 110
                Case 121 To 131
                    ret.shape = shape - 121
                Case 132 To 142
                    ret.shape = shape - 132

            End Select

            Select Case shape
                Case 0 To 10
                    ret.library = EvoLib.Protocol.ImgLibs.Magic
                Case 11 To 21
                    'ret.library = EvoLib.Protocol.ImgLibs.MWeapon2
                Case 22 To 32
                    'ret.library = EvoLib.Protocol.ImgLibs.MWeapon3
                Case 33 To 43
                    'ret.library = EvoLib.Protocol.ImgLibs.MWeapon4
                Case 44 To 54
                    'ret.library = EvoLib.Protocol.ImgLibs.MWeapon5
                Case 55 To 65
                    'ret.library = EvoLib.Protocol.ImgLibs.MWeapon6
                Case 66 To 76
                    'ret.library = EvoLib.Protocol.ImgLibs.MWeapon7
                Case 77 To 87
                    'ret.library = EvoLib.Protocol.ImgLibs.MWeapon10
                Case 88 To 98
                    'ret.library = EvoLib.Protocol.ImgLibs.MWeapon11
                Case 99 To 109
                    'ret.library = EvoLib.Protocol.ImgLibs.MWeaponADL1
                Case 110 To 120
                    'ret.library = EvoLib.Protocol.ImgLibs.MWeaponADR1
                Case 121 To 131
                    'ret.library = EvoLib.Protocol.ImgLibs.MWeaponAOH1
                Case 132 To 142
                    'ret.library = EvoLib.Protocol.ImgLibs.MWeaponAOH2
            End Select

            Return ret

        End Function

    End Module

End Namespace
